<template>
  <div class="app-container">
    <div class="filter-container">
      撤销原因：<span>{{fileAddress}}</span>
      <br/>
       <br/>

      <img src=fileAddress />

    </div>


  </div>
</template>

<script>
  // import {fetchBankupByIds,insertBankup} from './tmpt-list-api'
  import waves from '@/directive/waves' // waves directive

  export default {
    name: 'TmptBankupRestore',
    directives: { waves },

    props: {
      //撤销原因
      remark:'',
      fileAddress:'',
      isModule: {
        type: Boolean,
        default: false
      },
      row: {}
    },
    data() {
      return {


      }
    },
    watch: {
      'row': {
        immediate: true, // vue首次赋值不触发watch的解决方法
        handler: function(nval) {
          if (this.isModule) {
            // this.temp = Object.assign({}, this.row) // copy obj
            if (this.isNull(nval)) {
              return
            }
            if (this.isNull(nval.id)) {
              return
            }
            this.getList(nval.id)
          }
        }
      }
    },

    methods: {
      withdrawAgree() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$confirm('确认同意撤销吗？').then(_ => {
              const param = { id: this.temp.id }
              //项目状态改为提交
              param.status = 3
              createApi(param).then((r) => {
                this.notify(r)
                if (r.success) {
                  this.resetTemp()
                  // 从父组件调用此方法，进行回调下
                  if (this.isModule) {
                    this.$emit('withdrawResult')
                  }
                }
              })
              // end
            })
              .catch(_ => {
              })

          }
        })

      },
      withdrawReject() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$confirm('确认撤销吗？').then(_ => {
              const param = { id: this.temp.id }
              //项目状态改为提交
              param.status = 0
                            createApi(param).then((r) => {
                this.notify(r)
                if (r.success) {
                  this.resetTemp()
                  // 从父组件调用此方法，进行回调下
                  if (this.isModule) {
                    this.$emit('withdrawResult')
                  }
                }
              })
              // end
            })
              .catch(_ => {
              })

          }
        })

      },
      onClickDownDaily(name, val) {
        let s = JSON.stringify(val)
        var export_blob = new Blob([s])
        var save_link = document.createElement('a')
        save_link.href = window.URL.createObjectURL(export_blob)
        save_link.download = name
        this.fakeClick(save_link)
      },
      fakeClick(obj) {
        var ev = document.createEvent('MouseEvents')
        ev.initMouseEvent(
          'click',
          true,
          false,
          window,
          0,
          0,
          0,
          0,
          0,
          false,
          false,
          false,
          false,
          0,
          null
        )
        obj.dispatchEvent(ev)
      },
      beforeUpload(file) {
        this.fileList = [file]
        // console.log('选择了文件beforeUpload')
        // 读取数据
        this.read(file)
        return false
      },
      read(f) {
        let rd = new FileReader()
        const _this = this
        _this.fileListStr = ''
        rd.onload = e => {
          //this.readAsArrayBuffer函数内，会回调this.onload函数。在这里处理结果
          let cont = rd.reading({ encode: 'utf-8' })
          console.log(cont)
          _this.fileListStr = cont
        }
        rd.readAsBinaryString(f)
      }
    }

  }
</script>

<style>
  .sortable-ghost {
    opacity: .8;
    color: darkgreen !important;
    background: #42b983 !important;
  }
</style>

<style scoped>
  .icon-star {
    margin-right: 2px;
  }

  .drag-handler {
    width: 20px;
    height: 20px;
    cursor: pointer;
  }

  .show-d {
    margin-top: 15px;
  }
</style>
